package com.nut.course.util;

import java.math.BigDecimal;

public class MathUtil {

    public static final BigDecimal HUNDRED = new BigDecimal(100);
    public static final BigDecimal THOUSAND = new BigDecimal(1000);
    public static final BigDecimal TEN_THOUSAND = new BigDecimal(10000);

    public static final int toFen(String val) {
        BigDecimal dd = new BigDecimal(val).multiply(HUNDRED);
        return dd.intValue();
    }

    public static final int toPoint(String val) {
        BigDecimal dd = new BigDecimal(val);
        return dd.intValue();
    }

    public static final BigDecimal toYuan(Integer val) {
        BigDecimal dd = new BigDecimal(val).divide(HUNDRED);
        return dd;
    }

    public static final Integer discount(Integer total, Integer discount) {
        BigDecimal dd = new BigDecimal(total).multiply(new BigDecimal(discount).divide(HUNDRED));
        return dd.intValue();
    }

    public static final Integer getScore(Integer payMoney, Integer scoreTimes) {
        BigDecimal dd = new BigDecimal(payMoney).multiply(new BigDecimal(scoreTimes)).divide(TEN_THOUSAND);
        return dd.intValue();
    }

    public static void main(String[] args) {

        Integer discount = discount(200, 95);

        BigDecimal bigDecimal = toYuan(1);
        System.out.println(bigDecimal);

//        String day = "2020-02-03";
//        System.out.println(toIntDay(day));

        String ff = "102.897";
        String ff2 = "102.0003";
        System.out.println(toFen(ff));
        System.out.println(toFen(ff2));
    }
}
